//
//  ViewController.swift
//  imm_drawer
//
//  Created by MengZhiZhi on 04/18/2025.
//  Copyright (c) 2025 MengZhiZhi. All rights reserved.
//

import UIKit
import imm_drawer

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let config = FZDrawerConfig()
        let vc1 = MainViewController()
        vc1.view.backgroundColor = .yellow
        config.mainDrawerVc = vc1
        let vc2 = UIViewController()
        vc2.view.backgroundColor = .blue
        config.leftDrawerVc = vc2
        let vc3 = UIViewController()
        vc3.view.backgroundColor = .green
        config.rightDrawerVc = vc3
        config.leftDrawerWidth = 300
        config.rightDrawerWidth = view.bounds.width * 0.7
        config.isEnableGestures = false
        let mainVc = FZMainDrawerViewController(config: config)
        self.view.addSubview(mainVc.view)
        self.addChildViewController(mainVc)
        mainVc.view.frame = self.view.bounds
        
        // 添加阴影
        let rightShadowImgView = UIImageView(image: UIImage(named: "shadow_right"))
        mainVc.overlayView.addSubview(rightShadowImgView)
        rightShadowImgView.frame = CGRect(x:mainVc.overlayView.frame.width - 9 , y: 0, width: 9, height: mainVc.overlayView.frame.height)
        
        // 添加阴影
        let leftShadowImgView = UIImageView(image: UIImage(named: "shadow_left"))
        mainVc.overlayView.addSubview(leftShadowImgView)
        leftShadowImgView.frame = CGRect(x:0 , y: 0, width: 9, height: mainVc.overlayView.frame.height)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

class MainViewController:UIViewController{
    lazy var imgView:UIImageView = {
        let imgView = UIImageView()
        return imgView
    }()
    
    lazy var bottomTableView:UITableView = {
        let view = UITableView()
        view.backgroundColor = .clear
        return view
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.addSubview(imgView)
        imgView.frame = view.frame
        
        let backgroundImage = UIImage(named: "home_test")
        imgView.image = backgroundImage
        
        self.view.addSubview(bottomTableView)
        bottomTableView.frame = view.frame
        
        bottomTableView.delegate = self
        bottomTableView.dataSource = self
        bottomTableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        
    }
}

extension MainViewController:UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 30
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 150
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.backgroundColor = UIColor.white.withAlphaComponent(0.3)
        cell.selectionStyle = .none
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if FZDrawerManager.shared.isOpen{
            FZDrawerManager.shared.closeRightDrawer()
        }else{
            FZDrawerManager.shared.openRightDrawer()
        }
    }
    
}

